const cloud = require('wx-server-sdk')
cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()

exports.main = async (event, context) => {
    const { tipId } = event
    const wxContext = cloud.getWXContext()

    try {
        // 检查用户是否已点赞
        const likeRes = await db.collection('tipLikes')
            .where({
                tipId: tipId,
                openid: wxContext.OPENID
            })
            .count()

        return {
            code: 0,
            data: {
                isLiked: likeRes.total > 0
            }
        }
    } catch (err) {
        console.error('检查点赞状态失败:', err)
        return {
            code: -1,
            message: '检查失败'
        }
    }
}